Add a function for creating a domain from an existing XendConfig, and use that
authorEwan Mellor <ewan@xensource.com>
Thu, 21 Dec 2006 17:39:32 +0000 (17:39 +0000)
committerEwan Mellor <ewan@xensource.com>
Thu, 21 Dec 2006 17:39:32 +0000 (17:39 +0000)
on reboot, rather than writing out sxp and reparsing.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py

index 81c39384d40cb60412ac3e386fc196edf93bcc93..ce6d48776677d6687f919fde4a2671eb6fddb556 100644 (file)
@@ -869,6 +869,26 @@ class XendDomain:
             self.domains_lock.release()
 
 
+    def domain_create_from_dict(self, config_dict):
+        """Create a domain from a configuration dictionary.
+
+        @param config_dict: configuration
+        @rtype: XendDomainInfo
+        """
+        self.domains_lock.acquire()
+        try:
+            self._refresh()
+
+            dominfo = XendDomainInfo.create_from_dict(config_dict)
+            self._add_domain(dominfo)
+            self.domain_sched_credit_set(dominfo.getDomid(),
+                                         dominfo.getWeight(),
+                                         dominfo.getCap())
+            return dominfo
+        finally:
+            self.domains_lock.release()
+
+
     def domain_new(self, config):
         """Create a domain from a configuration but do not start it.
         
index 416c0e67feaf5c11fcbb4c6572961c38fd1ea041..6bd11899b67209d518002a26559604a701e5acc3 100644 (file)
@@ -81,13 +81,12 @@ log = logging.getLogger("xend.XendDomainInfo")
 
 def create(config):
     """Creates and start a VM using the supplied configuration. 
-    (called from XMLRPCServer directly)
 
     @param config: A configuration object involving lists of tuples.
     @type  config: list of lists, eg ['vm', ['image', 'xen.gz']]
 
     @rtype:  XendDomainInfo
-    @return: A up and running XendDomainInfo instance
+    @return: An up and running XendDomainInfo instance
     @raise VmError: Invalid configuration or failure to start.
     """
 
@@ -102,6 +101,28 @@ def create(config):
 
     return vm
 
+def create_from_dict(config_dict):
+    """Creates and start a VM using the supplied configuration. 
+
+    @param config_dict: An configuration dictionary.
+
+    @rtype:  XendDomainInfo
+    @return: An up and running XendDomainInfo instance
+    @raise VmError: Invalid configuration or failure to start.
+    """
+
+    log.debug("XendDomainInfo.create_from_dict(%s)",
+              scrub_password(config_dict))
+    vm = XendDomainInfo(XendConfig.XendConfig(xapi = config_dict))
+    try:
+        vm.start()
+    except:
+        log.exception('Domain construction failed')
+        vm.destroy()
+        raise
+
+    return vm
+
 def recreate(info, priv):
     """Create the VM object for an existing domain.  The domain must not
     be dying, as the paths in the store should already have been removed,
@@ -1051,12 +1072,6 @@ class XendDomainInfo:
         """
         from xen.xend import XendDomain
         
-        config = self.sxpr()
-
-        if self._infoIsSet('cpus') and len(self.info['cpus']) != 0:
-            config.append(['cpus', reduce(lambda x, y: str(x) + "," + str(y),
-                                          self.info['cpus'])])
-
         if self._readVm(RESTART_IN_PROGRESS):
             log.error('Xend failed during restart of domain %s.  '
                       'Refusing to restart to avoid loops.',
@@ -1097,7 +1112,8 @@ class XendDomainInfo:
 
             new_dom = None
             try:
-                new_dom = XendDomain.instance().domain_create(config)
+                new_dom = XendDomain.instance().domain_create_from_dict(
+                    self.info)
                 new_dom.unpause()
                 rst_cnt = self._readVm('xend/restart_count')
                 rst_cnt = int(rst_cnt) + 1